<template>
  <div class="detailnavbar">
    <nav-bar>
      <div slot="left" @click="backHome" class="back">
        <img src="~assets/img/common/back.svg" alt="">
      </div>
      <div slot="center" class="title">
        <div 
          v-for="(item,index) in titles" 
          :key="index"
          :class="{active: index === currentIndex}"
          @click="change(index)"
        >{{item}}</div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar";
export default {
  name: "DetailNavBar",
  components: {
    NavBar
  },
  data() {
    return {
      titles: ['商品', '参数', '评论', '推荐'],
      currentIndex: 0,
    };
  },
  methods: {
    backHome() {
      this.$router.back()
    },
    change(index) {
      this.currentIndex = index
      this.$emit('titleClick', index)
    }
  }
};
</script>

<style scoped>
.back{
  margin-top: 6px;
  font-size: 12px;
}
.title {
  display: flex;
  justify-content: space-around;
  font-size: 15px;
}
.active{
  color: var(--color-high-text);
}
</style>